using System.Windows;
using SmartBoard.Book.Dialogs;

namespace SmartBoard.Book.Model
{
    public class BookManager
    {
        #region [Singleton]
        private static BookManager _instance = null;

        private BookManager()
        {
            DataManager = new BookDataManager();
        }

        public static BookManager Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new BookManager();
                return _instance;
            }
        }
        #endregion

        public bool CanCreateNewBook()
        {
            if(this.Book != null && !this.Book.IsEmpty)
            {
                return MessageBox.Show("A book is aready open. Do you want to discard it?", "Create New", MessageBoxButton.OKCancel) == MessageBoxResult.OK;
            }
            return true;
        }

        public void CreateNewBook()
        {
            var dialog = new CreateNewBookDialog();
            if (dialog.ShowDialog() == true)
            {
                var b = new Book
                            {
                                Name = dialog.BookName
                            };
                while (b.Pages.Count < dialog.PageCount)
                {
                    b.Pages.Add(new Page());
                }
                BookManager.Instance.Book = b;
            }
        }

        private Book _book;
        public Book Book
        {
            get
            {
                return _book;
            }
            set
            {
                _book = value;
            }
        }

        public IBookDataManager DataManager { get; private set; }

    }
}